
import os
import glob
import openpyxl
from datetime import datetime
from openpyxl.styles import Alignment

def wirteSheetHeader(sheet):
    sheet.cell(1, 1, "ID")
    sheet.cell(1, 2, "Available")

def read_files_in_directory(directory):
    file_list = []
    for filename in os.listdir(directory):
        if os.path.isfile(os.path.join(directory, filename)):
            file_list.append(filename)
    return file_list

def get_files(dir, suffix):
    py_files = []
    for root, dirs, files in os.walk(dir):  # 遍历所有目录，包括自身
        for file in files:  # 遍历文件，抓取指定文件
            pre, suf = os.path.splitext(file)
            if suf == suffix:
                py_files.append(os.path.join(file).split('.')[0])
    return py_files

if __name__ == "__main__":
    directory = '../../../vhal_platform/common'  # 替换为实际的目录
    file_extension = '.cpp'

    cpp_files = get_files(directory,".cpp")

    txt_path = 'Base_ID.txt'	# txt文本路径
    result=[]
    with open(txt_path,'r') as f:
        for line in f:
            result.append(line.strip('\n'))

    excle = openpyxl.load_workbook("BaseProp_ID.xlsx")
    sheetNames = excle.sheetnames
    for sheet in sheetNames:
        excle.remove(excle[sheet])

    sheet = excle.create_sheet("BasePropertyID")
    wirteSheetHeader(sheet)
    sheetColumns=['A','B']
    for sheet_column in sheetColumns:
        dimensions = sheet.column_dimensions[sheet_column]
        if sheet_column == 'A':
            dimensions.width = 60
        else:
            dimensions.width = 10

    index = 2
    # 创建新的内容
    for prop in result:
        sheet.cell(index, 1, prop)
        if cpp_files.__contains__(prop):
            sheet.cell(index,2,'是')
        else:
            sheet.cell(index,2,'否')
        index += 1
    excle.save("BaseProp_ID.xlsx")
